package github.kawaiior.yuanchuxiuzhen.common.gongfa.base;

import github.kawaiior.yuanchuxiuzhen.common.capability.entity.ManaPower;
import github.kawaiior.yuanchuxiuzhen.common.gongfa.GongFaBase;
import github.kawaiior.yuanchuxiuzhen.core.init.GongFaInit;
import github.kawaiior.yuanchuxiuzhen.core.registry.ModCapability;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class FenJinChiHuoJue extends GongFaBase {
    public FenJinChiHuoJue(String itemName) {
        super(ManaPower.ManaRoot.FIRE, 10000, GongFaInit.CHI_YAN_JUE, itemName);
    }


    @Override
    public void onPlayerLearn(PlayerEntity player, World world, ManaPower power) {

    }

    @Override
    public void onPlayerLearnFinish(PlayerEntity player, World world, ManaPower power) {
        // TODO: 添加效果
    }

    public static void onPlayerAttack(PlayerEntity player, World world, float amount, ManaPower power){
        learn(player, world, power, amount);
    }

    private static void learn(PlayerEntity player, World world, ManaPower power, float amount){
        if (!power.isLearningGongFa(GongFaInit.FEN_JIN_CHI_HUO_JUE)){
            return;
        }

        power.addGongFaExp(player, world, (int) amount);
    }

    // 效果
    public static void onPlayerAttackEvent(PlayerEntity player, LivingAttackEvent event, ManaPower power){
        if (!power.isLearnedGongFa(GongFaInit.FEN_JIN_CHI_HUO_JUE)){
            return;
        }

        LivingEntity living = event.getEntityLiving();
        if (!living.isImmuneToFire()){
            living.setFire(5);
        }
        player.addPotionEffect(new EffectInstance(Effects.STRENGTH, 200, 3));
    }

    public static void onPlayerTick(PlayerEntity player, ManaPower power){
        if (!power.isLearnedGongFa(GongFaInit.FEN_JIN_CHI_HUO_JUE)){
            return;
        }

        if (player.isPotionActive(Effects.FIRE_RESISTANCE)){
            return;
        }

        player.addPotionEffect(new EffectInstance(Effects.FIRE_RESISTANCE, 200000, 0));
    }

}
